import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt

img = cv.imread("assets/lena.jpg", 0)
plt.figure(figsize=(10,10))
plt.subplot(221)
plt.imshow(img, cmap="gray")

f = np.fft.fft2(img)
fshift = np.fft.fftshift(f)
fm_img = np.log(np.abs(fshift))

plt.subplot(222)
plt.imshow(fm_img, cmap="gray")

mask = np.ones_like(img)
mask_size = 40
cx,cy = int(mask.shape[1]/2), int(mask.shape[0]/2)
mask[cy-mask_size:cy+mask_size, cx-mask_size:cx+mask_size] = 0.

plt.subplot(223)
plt.imshow(mask, cmap="gray")

fmask = fshift * mask
img_new = np.fft.ifft2(fmask)
plt.subplot(224)
plt.imshow(np.abs(img_new), cmap="gray")

plt.show()